import { markRaw } from 'vue'
import StartNode from '@/components/node_types/start_node.vue'
import EndNode from '@/components/node_types/end_node.vue'
import ChatModelNode from '@/components/node_types/chatmodel_node.vue'
import ChatTemplateNode from '@/components/node_types/chattemplate_node.vue'
import NormalProperty from '@/components/node_properties/normal_property.vue'
import ChatModelProperty from '@/components/node_properties/chatmodel_property.vue'
import ChatTemplateProperty from '@/components/node_properties/chattemplate_property.vue'
import McpTemplateProperty from '@/components/node_properties/mcptemplate_property.vue'
import McpTemplateNode from '@/components/node_types/mcptemplate_node.vue'
import McpToolNode from '@/components/node_types/mcptool_node.vue'
import McpToolProperty from '@/components/node_properties/mcptool_property.vue'
import BranchNode from '@/components/node_types/branch_node.vue'
import BranchProperty from '@/components/node_properties/branch_property.vue'
import { Cpu } from '@element-plus/icons-vue'
import { DropShadowRight, DropShadowLeft, FormOne, Tool } from '@icon-park/vue-next'

export type NodeTypeKey = 'start' | "end" | 'chatmodel' | 'chatTemplate' | 'chatMcpTemplate' | 'mcpTool' | 'branch'
type CategoriesUnion = '起止节点' | '模型节点' | '工具节点' | '控制节点' | '其他' | '模板节点'

export interface NodeTemplate {
    type: NodeTypeKey,
    name: string,
    category: CategoriesUnion,
    isHide?: boolean,
    icon: any,
    serializableFields: string[],
    handleBounds?: [],
    defaultData: Record<string, any>,
    component: any,
    propertyComponent: any
}

export const nodeTemplates: Record<NodeTypeKey, NodeTemplate> = {
    start: {
        type: 'start',
        name: '开始节点',
        category: '起止节点',
        icon: markRaw(DropShadowRight),
        serializableFields: [],
        defaultData: {},
        component: markRaw(StartNode),
        propertyComponent: markRaw(NormalProperty)
    },
    end: {
        type: 'end',
        name: '结束节点',
        category: '起止节点',
        icon: markRaw(DropShadowLeft),
        serializableFields: [],
        defaultData: {},
        component: markRaw(EndNode),
        propertyComponent: markRaw(NormalProperty)
    },
    chatTemplate: {
        type: 'chatTemplate',
        name: '聊天模板节点',
        category: '模板节点',
        icon: markRaw(FormOne),
        serializableFields: [
            'systemmessage',
            'usermessage',
        ],
        defaultData: {
            systemmessage: '请使用中文回答问题。',
            usermessage: '请输入问题。',
        },
        component: markRaw(ChatTemplateNode),
        propertyComponent: markRaw(ChatTemplateProperty)
    },
    chatMcpTemplate: {
        type: 'chatMcpTemplate',
        name: 'MCP模板节点',
        category: '模板节点',
        icon: markRaw(FormOne),
        serializableFields: [
            'Id',
            'mcpName',
        ],
        defaultData: {
            Id: 0,
            mcpName: '未知MCP',
        },
        component: markRaw(McpTemplateNode),
        propertyComponent: markRaw(McpTemplateProperty)
    },
    mcpTool: {
        type: 'mcpTool',
        name: 'Mcp工具节点',
        category: '工具节点',
        icon: markRaw(Tool),
        serializableFields: [
            'Id',
            'mcpName',
        ],
        defaultData: {
            Id: 0,
            mcpName: '未知MCP',
        },
        component: markRaw(McpToolNode),
        propertyComponent: markRaw(McpToolProperty)
    },
    chatmodel: {
        type: 'chatmodel',
        name: '大模型节点',
        category: '模型节点',
        icon: markRaw(Cpu),
        serializableFields: [
            'model',
            'modelName',
            'mcpId',
            'scene',
            'inputField',
            'outputField',
            'maxContextLength',
            'temperature'
        ],
        defaultData: {
            model: '',
            modelName: '',
            mcpId: 0,
            scene: '你是一个',
            inputField: 'input_text',
            outputField: 'output_text',
            maxContextLength: 2048,
            temperature: 0.7,
        },
        component: markRaw(ChatModelNode),
        propertyComponent: markRaw(ChatModelProperty)
    },
    branch: {
        type: 'branch',
        name: '分支节点',
        category: '控制节点',
        icon: markRaw(Cpu),
        serializableFields: [
            'conditions',
        ],
        defaultData: {
            conditions: [
                {
                    id: "condition-default",
                    type: "default",
                    name: "默认分支",
                    scprit: "",
                }
            ]
        },
        component: markRaw(BranchNode),
        propertyComponent: markRaw(BranchProperty)
    }
}